﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArtemisExtensions
{
    public sealed class EventManager : ArtemisExtensions.IEventManager
    {

        private static EventManager instance;
        private System.Collections.Generic.Dictionary<int, ArtemisExtensions.IEventHandler> eventHandlers;
        private Queue<Event> eventQueue;

        private EventManager() { }

        public static EventManager Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new EventManager();
                }
                return instance;
            }
        }


        /// <summary>
        /// Listeners that may have information found on character sheets
        /// </summary>
        public EVHandler CharacterSheetListeners
        {
            get;
            set;
        }
    
        
        public bool HandleEvent(int eventcode, IEventInfo info)
        {
            
            //lookup list of event handlers for that code
            IEventHandler ie;
            eventHandlers.TryGetValue(eventcode, out ie);
            //then ask them to handle it
            return ie.HandleEvent(eventcode, info);
        }


        public bool TryAddHandler(IEventHandler eh)
        {
            throw new NotImplementedException();
            //cannot have two with the same int code
        }


        public bool Tick()
        {
            Event e = eventQueue.Dequeue();
            return HandleEvent(e.Code, e.EventInfo);
        }


        public void QueueEvent(EV_EventHandler eh, int evCode, IEventInfo ei)
        {
            throw new NotImplementedException();
        }

        public void TriggerEvent()
        {
            throw new NotImplementedException();
        }



        public void Initialize()
        {
            throw new NotImplementedException();

            //add technique manager as listener
            CharacterSheetListeners = TechniqueManager.Instance.HandleEvent;
        }
    }
}
